package com.aikg.kgrag_java.repository;

import com.aikg.kgrag_java.pojo.entity.neo4j.NodeRelation;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @ClassName: NodeRelationRepository
 * @Description: TODO
 * @Author: 李宗雨
 * @Date: 2025/1/4 22:13
 * @Version: 1.0
 **/
public interface NodeRelationRepository extends Neo4jRepository<NodeRelation, Long> {
    @Query("""
            match()-[r:RELATION where id(r)=$relationId]->()
            return r
            """)
    NodeRelation getNodeRelationById(@Param("relationId") Long id);



    /**
     * 检索重要节点的上下一跳
     * @param id: 重要节点的id
     * @return 上下一条节点
     */
    @Query("""
            match (n)-[r]->(m)
            where id(n) = $id
            return r.relationName as value, m as targetNode
            """)
    List<NodeRelation> lastAndNextNodeSearch(
            @Param("id") int id
    );
}
